﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using ESOL.Business.Mst;

namespace ESOL.WinUI.Bpt
{
    public partial class frmMaintainEncoderQuery : BaseForm.frmBaseDialogyQueryForm
    {
        #region Variable
        public List<string> ListIn { get; set; }
        public string SPassOut { get; set; }
        public string SType { get; set; }
        public List<string> aList { get; set; }
        #endregion

        #region Constructor
        public frmMaintainEncoderQuery()
        {
            InitializeComponent();
        }
        #endregion

        #region Functions
        private void GetByPassIn(List<string> PassInList, string sType)
        {
            DataTable dt = new DataTable();
            switch(sType)
            {
                case "BroadClassName":
                    dt = MstProductBs.GetBroadClass(PassInList[0], "");
                    if (dt!=null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "BroadClassCode":
                    dt = MstProductBs.GetBroadClass("", PassInList[1]);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "MiddleClassName":
                    dt = MstProductBs.GetMiddleClass(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "MiddleClassCode":
                    dt = MstProductBs.GetMiddleClass(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "TypeName":
                    dt = MstProductBs.GetType(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "TypeCode":
                    dt = MstProductBs.GetType(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "StdName":
                    dt = MstProductBs.GetStd(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "StdCode":
                    dt = MstProductBs.GetStd(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "MaterialName":
                    dt = MstProductBs.GetMaterial(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "MaterialCode":
                    dt = MstProductBs.GetMaterial(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "ProductCode":
                    dt = MstProductBs.GetProduct(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
                case "Remark":
                    dt = MstProductBs.GetRemark(PassInList);
                    if (dt != null)
                    {
                        gvMain.DataSource = dt;
                    }
                    break;
            }
        }

        #endregion

        #region Event
        protected override void OnShown(EventArgs e)
        {
            GetByPassIn(ListIn, SType);
            gvMain.Focus();
            base.OnShown(e);
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (dr == null)
            {
                return;
            }
            aList = new List<string>();
            string sNane = dr[1].ToString();
            string sCode = dr[0].ToString();
            aList.Add(sNane);
            aList.Add(sCode);
            this.DialogResult = DialogResult.OK;
        }

        private DataRow dr;
        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            dr = gridView1.GetDataRow(e.RowHandle);
        }

        private void gvMain_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }

        private void frmEncoderQuery_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }
        #endregion
    }
}
